<template>
  <div>
    <div class="form_wrap">
      <el-form label-width="120px" style="margin-top:10px">
        <!--end 按揭-->
        <div class="wrap clearfix">
          <div class="title">
            按揭信息：
            <div class="button">
              <el-button
                @click="openDiaAj"
                v-if="showMortBtn && orderStatus == 3"
                >{{ ajTitle }}</el-button
              >
            </div>
          </div>
          <div>
            <div class="li_wrap">
              <el-form-item class="posInput ts" label="按揭批款额度:">
                <span class="pos left">小写</span>
                <el-input
                  v-model="aj.contractGuaranteeMoney"
                  :disabled="true"
                ></el-input>
                <span class="pos right">（万元）</span>
              </el-form-item>
            </div>
          </div>
        </div>

        <!--end 收费-->
        <div class="wrap clearfix">
          <div class="title">
            财务信息:
            <div class="button">
              <el-button
                @click="openDiaCharge"
                v-if="showChargeBtn && orderStatus == 3"
                >{{ chargeTitle }}</el-button
              >
            </div>
          </div>
          <div>
            <el-row>
              <el-col :span="24">
                <div class="li_wrap">
                  <el-form-item class="posInput ts" label="核算点数:">
                    <el-input
                      v-model="cw.calculateRatio"
                      :disabled="true"
                      @input="this.$forceUpdate()"
                    ></el-input>
                    <span class="pos right">（%）</span>
                  </el-form-item>
                </div>
                <div class="li_wrap">
                  <el-form-item class="posInput ts" label="核算附加费:">
                    <el-input
                      v-model="cw.calculateAddMoney"
                      :disabled="true"
                      @input="this.$forceUpdate()"
                    ></el-input>
                    <span class="pos right">（元）</span>
                  </el-form-item>
                </div>
              </el-col>
              <el-col :span="24">
                <div class="li_wrap">
                  <el-form-item class="posInput ts" label="收费金额:">
                    <el-input
                      v-model="cw.chargeMoney"
                      :disabled="true"
                      @input="this.$forceUpdate()"
                    ></el-input>
                    <span class="pos right">（元）</span>
                  </el-form-item>
                </div>
                <div class="li_wrap">
                  <el-form-item label="实际收费时间:">
                    <el-date-picker
                      v-model="cw.chargeTime"
                      type="date"
                      placeholder="选择日期时间"
                      align="right"
                      :disabled="true"
                      :picker-options="pickerOptions"
                      @input="this.$forceUpdate()"
                    >
                    </el-date-picker>
                  </el-form-item>
                </div>
              </el-col>
            </el-row>
          </div>
        </div>
        <!--enf 放款-->
        <div class="wrap clearfix">
          <div class="title">
            放款信息:
            <div class="button">
              <el-button @click="openDiaFk" v-if="orderStatus == 3">{{
                dzTitle
              }}</el-button>
            </div>
          </div>
          <div>
            <div class="li_wrap">
              <el-form-item class="posInput ts" label="按揭金额:">
                <el-input
                  v-model="fk.lendingAmount"
                  :disabled="true"
                  @input="this.$forceUpdate()"
                ></el-input>
                <span class="pos right">（元）</span>
              </el-form-item>
            </div>
            <div class="li_wrap">
              <el-form-item label="放款时间:">
                <el-date-picker
                  v-model="fk.lendingTime"
                  type="date"
                  placeholder="选择日期时间"
                  align="right"
                  :disabled="true"
                  :picker-options="pickerOptions"
                  @input="this.$forceUpdate()"
                >
                </el-date-picker>
              </el-form-item>
            </div>
          </div>
        </div>
        <!--  -->
      </el-form>
    </div>
    <!--弹框-->
    <el-dialog
      title="编辑信息"
      :visible.sync="dialogTableVisible"
      v-if="dialogTableVisible && orderStatus == 3"
    >
      <el-form label-width="150px" v-if="showdis == 0" :model="diaDz">
        <el-row>
          <el-col :span="12">
            <el-form-item class="posInput ts" label="按揭批款额度:">
              <span class="pos left">小写</span>
              <el-input v-model="diaAj.contractGuaranteeMoney"></el-input>
              <span class="pos right">（万元）</span>
            </el-form-item>
          </el-col>
        </el-row>
        <div class="dialog-footer">
          <el-button @click="dialogTableVisible = false">取 消</el-button>
          <el-button type="primary" @click="submitAj">确 定</el-button>
        </div>
      </el-form>
      <el-form label-width="150px" v-if="showdis == 2" :model="diacw">
        <el-row>
          <el-col :span="12">
            <el-form-item
              class="posInput ts"
              label="核算点数:"
              prop="calculateRatio"
            >
              <el-input
                v-model="diacw.calculateRatio"
                @blur="countChangeMoney"
              ></el-input>
              <span class="pos right ht-right">（%）</span>
            </el-form-item></el-col
          >
          <el-col :span="12">
            <el-form-item
              class="posInput ts"
              label="核算附加费:"
              prop="calculateAddMoney"
            >
              <el-input
                v-model="diacw.calculateAddMoney"
                @blur="countChangeMoney"
              ></el-input>
              <span class="pos right ht-right">（元）</span>
            </el-form-item></el-col
          >
          <el-col :span="12">
            <el-form-item
              class="posInput ts"
              label="收费金额:"
              prop="chargeMoney"
            >
              <el-input v-model="diacw.chargeMoney"></el-input>
              <span class="pos right ht-right">（元）</span>
            </el-form-item></el-col
          >
          <el-col :span="12"
            ><el-form-item label="选择实际收费时间:" prop="chargeTime">
              <el-date-picker
                v-model="diacw.chargeTime"
                type="date"
                placeholder="选择日期时间"
                align="right"
                :picker-options="pickerOptions"
              >
              </el-date-picker> </el-form-item
          ></el-col>
        </el-row>
        <div class="dialog-footer">
          <el-button @click="dialogTableVisible = false">取 消</el-button>
          <el-button type="primary" @click="submitcharge">确 定</el-button>
        </div>
      </el-form>
      <el-form label-width="150px" v-if="showdis == 4" :model="diacw">
        <el-row>
          <el-col :span="12">
            <el-form-item
              class="posInput ts"
              label="按揭金额:"
              prop="contractGuaranteeMoney"
            >
              <el-input v-model="diacw.contractGuaranteeMoney"></el-input>
              <span class="pos right ht-right">（元）</span>
            </el-form-item></el-col
          >
          <el-col :span="12"
            ><el-form-item label="放款时间:" prop="lendingTime">
              <el-date-picker
                v-model="diacw.lendingTime"
                type="date"
                placeholder="选择日期时间"
                align="right"
                :picker-options="pickerOptions"
              >
              </el-date-picker> </el-form-item
          ></el-col>
        </el-row>
        <div class="dialog-footer">
          <el-button @click="dialogTableVisible = false">取 消</el-button>
          <el-button type="primary" @click="submitDz">确 定</el-button>
        </div>
      </el-form>
    </el-dialog>
    <el-dialog
      title="编辑信息"
      :visible.sync="dialogTableVisibleFk"
      v-if="orderStatus == 3"
    >
      <el-form label-width="150px" :model="diaFk">
        <el-row>
          <el-col :span="12">
            <el-form-item
              class="posInput ts"
              label="按揭金额:"
              prop="lendingAmount"
            >
              <el-input v-model="diaFk.lendingAmount"></el-input>
              <span class="pos right ht-right">（元）</span>
            </el-form-item></el-col
          >
          <el-col :span="12"
            ><el-form-item label="放款时间:" prop="lendingTime">
              <el-date-picker
                v-model="diaFk.lendingTime"
                type="date"
                placeholder="选择日期时间"
                align="right"
                :picker-options="pickerOptions"
              >
              </el-date-picker> </el-form-item
          ></el-col>
        </el-row>
        <div class="dialog-footer">
          <el-button @click="dialogTableVisibleFk = false">取 消</el-button>
          <el-button type="primary" @click="submitFk">确 定</el-button>
        </div>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import {
  getordinaryMort,
  putOrdinaryCharge,
  getProductUrl,
  putRedAcc,
  putOderRedAdv,
  putOrdinaryMort,
  getChargeCount
} from "../../../src/assets/js/api";
import { checkPermiss } from "../../assets/js/utlis";
import { GMTToStr } from "../../assets/js/utlis";
export default {
  name: "LoanInfor",
  props: ["orderNumber"],
  data() {
    return {
      dialogTableVisible: false,
      dialogTableVisibleFk: false,
      //按揭
      aj: {},
      diaAj: {},
      //赎楼
      sl: {},
      diaSl: {},
      //财务
      cw: {},
      diacw: {},
      //
      fk: {},
      diaFk: {},
      ajTitle: "修改",
      chargeTitle: "修改",
      slTitle: "修改",
      dzTitle: "修改",
      showdis: null,
      diaTitle: null,
      pickerOptions: {
        shortcuts: [
          {
            text: "今天",
            onClick(picker) {
              picker.$emit("pick", new Date());
            }
          },
          {
            text: "昨天",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit("pick", date);
            }
          },
          {
            text: "一周前",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", date);
            }
          }
        ]
      },
      options: [
        {
          value: "是",
          label: "是"
        },
        {
          value: "否",
          label: "否"
        }
      ],
      golbalPermissions: [],
      ProductUrl: "",
      orderStatus: ""
    };
  },
  created() {
    this.golbalPermissions = localStorage.getItem("permissions").split(",");
    this.status = eval(this.$route.query.status);
    if (!this.status) {
      this.getUpForm(this.orderNumber);
    }
    this.findProductUrl(this.orderNumber);
  },
  computed: {
    //按钮 按揭信息
    showMortBtn: function() {
      return checkPermiss("business:ordinary:mortgage", this.golbalPermissions);
    },
    //按钮 财务信息
    showChargeBtn: function() {
      return checkPermiss("business:ordinary:charge", this.golbalPermissions);
    },
    //按钮 放款信息
    showAdvanceBtn: function() {
      return checkPermiss("business:ordinary:advance", this.golbalPermissions);
    }
  },
  watch: {
    "aj.contractGuaranteeMoney": {
      handler(newName) {
        if (!newName) {
          this.ajTitle = "添加数据";
        } else {
          this.ajTitle = "修改";
        }
      }
    },
    "sl.accountName": {
      handler(newName) {
        if (!newName) {
          this.slTitle = "添加数据";
        } else {
          this.slTitle = "修改";
        }
      }
    },
    "cw.chargeMoney": {
      handler(newName) {
        if (!newName) {
          this.chargeTitle = "添加数据";
        } else {
          this.chargeTitle = "修改";
        }
      }
    },
    "fk.lendingAmount": {
      handler(newName) {
        if (!newName) {
          this.dzTitle = "添加数据";
        } else {
          this.dzTitle = "修改";
        }
      }
    }
  },
  methods: {
    //填写核算点数，核算附加费算出收费
    countChangeMoney() {
      if (this.diacw.calculateRatio && this.diacw.calculateAddMoney) {
        getChargeCount({
          orderNumber: this.orderNumber,
          calculateRatio: this.diacw.calculateRatio,
          calculateAddMoney: this.diacw.calculateAddMoney
        }).then(res => {
          this.diacw.chargeMoney = res.data;
        });
      } else if (!this.diacw.calculateRatio) {
        this.$message.warning("请输入核算点数");
      } else {
        this.$message.warning("请输入核算附加费");
      }
    },
    //根据订单查询路由path路径
    findProductUrl(orderNumber) {
      getProductUrl({
        orderNumber: orderNumber
      }).then(res => {
        this.ProductUrl = res.data.productUrl;
        this.orderStatus = res.data.orderStatus;
      });
    },
    //根据订单号查询当前信息
    getUpForm(orderNumber) {
      getordinaryMort(orderNumber).then(res => {
        let data = res.data;
        //按揭
        this.$set(
          this.aj,
          "contractGuaranteeMoney",
          data.contractGuaranteeMoney
        );
        //财务
        this.$set(this.cw, "chargeMoney", data.chargeMoney);
        this.$set(this.cw, "chargeTime", data.chargeTime);
        this.$set(this.cw, "calculateRatio", data.calculateRatio);
        this.$set(this.cw, "calculateAddMoney", data.calculateAddMoney);

        //垫资
        this.$set(this.fk, "lendingAmount", data.lendingAmount);
        this.$set(this.fk, "lendingTime", data.lendingTime);
      });
    },
    //按揭
    openDiaAj() {
      this.showdis = 0;
      this.dialogTableVisible = true;
      this.diaAj = JSON.parse(JSON.stringify(this.aj));
    },
    //赎楼
    openDiaSl() {
      this.showdis = 1;
      this.dialogTableVisible = true;
      this.diaSl = JSON.parse(JSON.stringify(this.sl));
    },
    //财务
    openDiaCharge() {
      this.showdis = 2;
      this.dialogTableVisible = true;
      this.diacw = JSON.parse(JSON.stringify(this.cw));
    },
    //放款
    openDiaFk() {
      this.dialogTableVisibleFk = true;
      this.diaFk = JSON.parse(JSON.stringify(this.fk));
    },
    //按揭提价按钮
    submitAj() {
      this.diaAj.orderNumber = this.orderNumber;
      putOrdinaryMort(this.diaAj).then(res => {
        if (res.code == 200) {
          this.getUpForm(this.orderNumber);
          this.dialogTableVisible = false;
          this.$message.success(res.message);
        }
      });
    },
    //赎楼信息提交按钮
    submitSl() {
      this.diaSl.orderNumber = this.orderNumber;
      if (this.diaSl.justTime) {
        this.diaSl.justTime = GMTToStr(this.diaSl.justTime);
      }
      putRedAcc(this.diaSl).then(res => {
        if (res.code == 200) {
          this.getUpForm(this.orderNumber);
          this.dialogTableVisible = false;
          this.$message.success(res.message);
        }
      });
    },
    //财务提价按钮
    submitcharge() {
      this.diacw.orderNumber = this.orderNumber;
      if (this.diacw.chargeTime) {
        this.diacw.chargeTime = GMTToStr(this.diacw.chargeTime);
      }
      putOrdinaryCharge(this.diacw).then(res => {
        if (res.code == 200) {
          this.getUpForm(this.orderNumber);
          this.dialogTableVisible = false;
          this.$message.success(res.message);
        }
      });
    },
    //放款按钮
    submitFk() {
      this.diaFk.orderNumber = this.orderNumber;
      if (this.diaFk.lendingTime) {
        this.diaFk.lendingTime = GMTToStr(this.diaFk.lendingTime);
      }
      putOderRedAdv(this.diaFk).then(res => {
        if (res.code == 200) {
          this.getUpForm(this.orderNumber);
          this.dialogTableVisibleFk = false;
          this.$message.success(res.message);
        }
      });
    }
  }
};
</script>

<style scoped type="less">
.posInput {
  position: relative;
}
.pos {
  position: absolute;
  z-index: 2;
}
.pos.left {
  left: 10px;
}
.pos.right {
  right: 0;
}
.posInput ::v-deep .el-input__inner {
  padding: 0 50px 0 40px;
  text-align: center;
}
.posInput.ts ::v-deep .el-input__inner {
  padding-left: 25px;
}
.toBe {
  line-height: 35px;
}
.form_wrap ::v-deep .el-form-item,
.form_wrap ::v-deep .el-form-item__label,
.form_wrap ::v-deep .el-form-item__content,
.form_wrap ::v-deep .el-input,
.form_wrap ::v-deep .el-input__inner {
  height: 32px;
  line-height: 32px;
  width: 280px;
}
.form_wrap ::v-deep .el-form-item {
  margin-bottom: 5px;
}
.form_wrap ::v-deep .el-col {
  line-height: 32px;
}
.form_wrap ::v-deep .el-button {
  padding: 8px 20px;
}
.form_wrap ::v-deep.el-input__icon {
  line-height: 24px;
}
::v-deep .el-form-item__content {
  text-align: left;
}
.el-date-editor.el-input {
  width: auto;
}
.li_wrap {
  width: 25%;
  min-width: 250px;
  float: left;
}
.form_wrap .wrap {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid rgba(238, 238, 238, 1);
  border-radius: 8px;
  padding: 5px 10px;
  margin-bottom: 5px;
}
.form_wrap .title {
  text-align: left;
  font-size: 15px;
  font-family: Microsoft YaHei;
  font-weight: bold;
  color: rgba(51, 51, 51, 1);
  line-height: 40px;
}
.form_wrap .button {
  float: right;
}
</style>
